/**
 * // Definition for a _Node.
 * function _Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {_Node|null} root
 * @return {number[][]}
 */
var levelOrder = function(root) {
    if(root === null) return []
    let res = [],
    levelArr,
    queue = [root];

    while(queue.length>0){
        let node,
        len = queue.length,
        levelArr = [];

        for(let i = 0;i<len;i++){
            node = queue.shift()
            for(let j = 0;j<node.children.length;j++){
                queue.push(node.children[j])
            }
            levelArr.push(node.val)
        }

        res.push(levelArr)
    }

    return res
};